package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "C端店铺控制器")
@RequestMapping("/user/shop")
public class UserShopController {

    public static final String KEY="SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 用户端营业状态(day05任务五)
     * @return
     */
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        log.info("[获取营业状态]");
        Integer status =(Integer) redisTemplate.opsForValue().get(KEY);
        if (status == null){
            redisTemplate.opsForValue().set(KEY,1);
            status=1;
        }
        return Result.success(status);
    }
}
